package com.zrrd.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @author WanJl
 * @version 1.0
 * @title RedisConfig
 * @description Redis配置类，进行一些自定义配置，主要就是配置key的序列化方式
 * @create 2023/8/15 11:44
 */
@Configuration
public class RedisConfig extends CachingConfigurerSupport {
    @Bean
    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<Object, Object> template = new RedisTemplate();
        //设置templete的序列化器
        //key的序列化方式
        template.setKeySerializer(new StringRedisSerializer());
        //value序列化方式不需要修改


        template.setHashKeySerializer(new StringRedisSerializer());


        template.setConnectionFactory(redisConnectionFactory);
        return template;
    }
}
